﻿namespace Common
{
    public class JsonUtils
    {
        /// <summary>
        /// 将Json字符串转换为指定类型的对象
        /// </summary>
        /// <typeparam name="T">指定类型</typeparam>
        /// <param name="jsonTxt">json字符串</param>
        /// <returns></returns>
        public static T ConvertJsonToObject<T>(string jsonTxt)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonTxt);
        }

        /// <summary>
        /// 将对象转换成Json字符串
        /// </summary>
        /// <param name="obj">需要转换的json字符串</param>
        /// <returns></returns>
        public static string ConvertObjectToJson(object obj)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        }
    }
}